/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.gui.documents.toolbox;

import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.jdesktop.swingx.JXTree;

/**
 *
 * @author stephane
 */
public class ExplorerTreeView extends JXTree implements MouseListener {

    private static final long serialVersionUID = 1L;

    public ExplorerTreeView() {
        installListener();
    }

    public ExplorerTreeView(TreeModel model) {
        super(model);
        installListener();
    }

    private void installListener() {
        this.addMouseListener(this);
        
    }

    @Override
    public void mouseClicked(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
        TreePath tp = getUI().getClosestPathForLocation(this, e.getX(), e.getY());
        if (tp != null) {
            Rectangle bounds = getPathBounds(tp);
            if (e.getY() < bounds.y + bounds.height) {
                setSelectionPath(tp);
            }
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }
}
